from unittest.mock import Mock
# 模拟mock 封装
# 貌似不用mock代码量还能更少？？？
class MockDemo:
	def __init__(self):
		# self.run = RunMethod.run_main()
		pass
	def mock_data(self,data):
		res_data01 = {'key': 'rd1'}
		res_data02 = {'key': 'rd2'}
		res_data_er = {'key': 'data错误！'}
		if data == '01':
			res = res_data01
		elif data == '02':
			res = res_data02
		else:
			res = res_data_er
		return res
	def mock_headers(self,headers):
		res_headers_er = {'error':'请求头错误！'}
		if headers == 'h1':
			res = 'y'
		else:
			res = res_headers_er
		return res
	def mock_method(self,method):
		res_method = {'error': '请求方式错误！'}
		if method =='get':
			res = 'y'
		else:
			res = res_method
		return res
	def mock_url(self,url):
		res_url = '404 Not Found!'
		if url == '123.com':
			res = 'y'
		else:
			res = res_url
		return res
	def mock_test(self,method,url,headers,data):
		mock_method = self.mock_method(method)
		mock_url = self.mock_url(url)
		mock_headers = self.mock_headers(headers)
		mock_data = self.mock_data(data)
		if mock_url == 'y':
			if mock_method =='y':
				if mock_headers == 'y':
					res = mock_data
				else:
					res =mock_headers
			else:
				res = mock_method
		else:
			res = mock_url
		# mock_method = Mock(return_value=res_data_er)
		return res

	def demo(self):
		method = 'get'
		url = '123.com'
		data = '01'
		header = 'h1'
		res = self.mock_test(method,url,header,data)
		print(res)

if __name__ == '__main__':
	MockDemo().demo()
